﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace BBCodeParser.Nodes
{
	public class TextNode : Node
	{
		private readonly string text;

		public TextNode(string text)
		{
			this.text = text;
		}

		internal override string ToHtml(Dictionary<string, string> substitutions, Func<Node, bool> filter = null)
		{
			return substitutions.Aggregate(text, (current, substitution) => current.Replace(substitution.Key, substitution.Value));
		}

	    internal override string ToText(Dictionary<string, string> substitutions)
	    {
	        return substitutions.Aggregate(text, (current, substitution) => current.Replace(substitution.Key, substitution.Value));
	    }

	    public override string ToBb(Dictionary<string, string> substitutions)
	    {
		    return substitutions == null
			    ? text
			    : substitutions.Aggregate(text, (current, substitution) => current.Replace(substitution.Key, substitution.Value));
	    }

		public override void AddChild(Node node)
		{
			throw new NotImplementedException();
		}
	}
}